<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="文件系统的使用 挂载和卸载mount 和 umount根文件系统以为的文件系统要想能够被访问,必须通过 “关联” 至根文件系统的某个目录上，此关联即为 “挂载” ；此目录即为 “挂载点” ；mount_point：用于作为另一个文件系统的访问入口；  事先存在 应该使用未被或者不会被其他进程使用到的目录； 挂载点下原有的文件会被隐藏；（最好是使用原来是空的目录）；mount命令：123456789">
<meta property="og:type" content="article">
<meta property="og:title" content="文件系统的挂载和使用">
<meta property="og:url" content="http://yoursite.com/2020/05/05/2-%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%8C%82%E8%BD%BD%E5%92%8C%E4%BD%BF%E7%94%A8/index.html">
<meta property="og:site_name" content="Lcxiao&#39;s blog">
<meta property="og:description" content="文件系统的使用 挂载和卸载mount 和 umount根文件系统以为的文件系统要想能够被访问,必须通过 “关联” 至根文件系统的某个目录上，此关联即为 “挂载” ；此目录即为 “挂载点” ；mount_point：用于作为另一个文件系统的访问入口；  事先存在 应该使用未被或者不会被其他进程使用到的目录； 挂载点下原有的文件会被隐藏；（最好是使用原来是空的目录）；mount命令：123456789">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-05T22:59:43.000Z">
<meta property="article:modified_time" content="2020-05-06T15:16:55.503Z">
<meta property="article:author" content="lcxiao">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/05/05/2-%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%8C%82%E8%BD%BD%E5%92%8C%E4%BD%BF%E7%94%A8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>文件系统的挂载和使用 | Lcxiao's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Lcxiao's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Lcxiao's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-lifestyle">

    <a href="/lifestyle/" rel="section"><i class="fa fa-fw fa-lifestyle"></i>LifeStyle</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/05/05/2-%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%8C%82%E8%BD%BD%E5%92%8C%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          文件系统的挂载和使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-05-06 06:59:43 / 修改时间：23:16:55" itemprop="dateCreated datePublished" datetime="2020-05-06T06:59:43+08:00">2020-05-06</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="文件系统的使用-挂载和卸载"><a href="#文件系统的使用-挂载和卸载" class="headerlink" title="文件系统的使用 挂载和卸载"></a>文件系统的使用 挂载和卸载</h2><p><code>mount</code> 和 <code>umount</code><br>根文件系统以为的文件系统要想能够被访问,必须通过 “关联” 至根文件系统的某个目录上，此关联即为 “挂载” ；此目录即为 “挂载点” ；<br>mount_point：用于作为另一个文件系统的访问入口；</p>
<ol>
<li>事先存在</li>
<li>应该使用未被或者不会被其他进程使用到的目录；</li>
<li>挂载点下原有的文件会被隐藏；（最好是使用原来是空的目录）；<h3 id="mount命令："><a href="#mount命令：" class="headerlink" title="mount命令："></a>mount命令：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">mount [-fnrsvw] [-t vfstype] [-o options] device dir</span><br><span class="line">    -r： readonly，只读挂载（比如光盘）；</span><br><span class="line">    -w: read and write 读写挂载；</span><br><span class="line">    -n： 默认情况下，设备挂载或者卸载的操作会同步更新至&#x2F;etc&#x2F;mtab文件中，-n用于禁止此特性；</span><br><span class="line">    -t vfstype：指明要挂载的设备上的文件系统的类型，多数情况下可自动识别，mount会通过blkid来判断要挂载的设备的文件系统类型；</span><br><span class="line">    -L LABEL： 挂载是以卷标的方式指明设备；</span><br><span class="line">    -U UUID DIR: 通过UUID挂载设备；</span><br><span class="line">    -o: 挂载选项；</span><br><span class="line">        sync&#x2F;async: 同步&#x2F;异步操作；（异步是先写入内存，随后写入磁盘，性能好，但安全行肯定没有同步安全）</span><br><span class="line">        atime&#x2F;noatime: 每个文件或目录被访问时是否立即更新其访问时间戳；</span><br><span class="line">        diratime&#x2F;nodiratime: 每个目录被访问时是否立即更新其访问时间戳；</span><br><span class="line">        remount: 重新挂载</span><br><span class="line">        acl: 支持使用acl功能；</span><br><span class="line">        mount -o acl DEVICE DIR</span><br><span class="line">        tune2fs -o acl device</span><br><span class="line">        ro： 只读</span><br><span class="line">        rw： 读写</span><br><span class="line">        dev&#x2F;nodev： 此设备上是否允许创建设备文件；</span><br><span class="line">        exec&#x2F;noexec： 是否允许运行此设备上的文件；</span><br><span class="line">        auto&#x2F;noauto： 是否允许自动运行；</span><br><span class="line">        user&#x2F;nouser： 是否允许普通用户挂载此文件系统；</span><br><span class="line">        suid&#x2F;nosuid： 是否允许程序文件上的suid和sgid特殊权限生效；</span><br><span class="line">        defaults： 使用默认选项：rw，suid，dev，exec，auto，nouser和async。</span><br><span class="line">            请注意，所有默认安装选项的实际设置取决于内核和文件系统类型。</span><br><span class="line">技巧：可以实现将目录绑定至另一个目录上，作为其临时访问入口</span><br><span class="line">mount --bind 源目录 目标目录</span><br></pre></td></tr></table></figure>
mount -r /dev/cdrom mount_point<h5 id="光盘设备一般为："><a href="#光盘设备一般为：" class="headerlink" title="光盘设备一般为："></a>光盘设备一般为：</h5> /dev/cdrom<br> /dev/dvd<br> /dev/sr0<h5 id="挂载U盘："><a href="#挂载U盘：" class="headerlink" title="挂载U盘："></a>挂载U盘：</h5> 事先识别U盘的设备文件：<h5 id="挂载本地回环设备；"><a href="#挂载本地回环设备；" class="headerlink" title="挂载本地回环设备；"></a>挂载本地回环设备；</h5> mount -o loop /PATH/TO?SOME_LOOP_FILE MOUNT_POINT<br> 例如ISO镜像文件<h4 id="查看当前已挂载的设备"><a href="#查看当前已挂载的设备" class="headerlink" title="查看当前已挂载的设备:"></a>查看当前已挂载的设备:</h4> mount<br> cat /proc/mounts<br> cat /etc/mtab</li>
</ol>
<h3 id="查看挂载设备被哪些进程所占用"><a href="#查看挂载设备被哪些进程所占用" class="headerlink" title="查看挂载设备被哪些进程所占用"></a>查看挂载设备被哪些进程所占用</h3><pre><code>fuser -v MOUNT_POINT
lsof MOUNT_POINT</code></pre><h3 id="终止所有正在访问某挂载点的进程："><a href="#终止所有正在访问某挂载点的进程：" class="headerlink" title="终止所有正在访问某挂载点的进程："></a>终止所有正在访问某挂载点的进程：</h3><pre><code>fuser -km MOUNT_POINT</code></pre><h3 id="umount命令："><a href="#umount命令：" class="headerlink" title="umount命令："></a>umount命令：</h3><pre><code>umount device | dir</code></pre><p>注意：正在被进程访问到的挂载点无法被卸载：</p>
<h3 id="交换分区"><a href="#交换分区" class="headerlink" title="交换分区"></a>交换分区</h3><pre><code>mkswap
启用：swapon
    -a 所有swap文件；(定义在fstab文件中的swap设备)；
禁用：swapoff
    swapoff DEVICE</code></pre><h3 id="设定除根文件系统以外的其他文件系统能够开机时自动挂载：-etc-fstab文件"><a href="#设定除根文件系统以外的其他文件系统能够开机时自动挂载：-etc-fstab文件" class="headerlink" title="设定除根文件系统以外的其他文件系统能够开机时自动挂载： /etc/fstab文件"></a>设定除根文件系统以外的其他文件系统能够开机时自动挂载： /etc/fstab文件</h3><table>
<thead>
<tr>
<th>要挂载的设备</th>
<th>挂载点</th>
<th>文件系统类型</th>
<th>挂载选项</th>
<th>转储频率（备份）</th>
<th>自检次序</th>
</tr>
</thead>
<tbody><tr>
<td>设备文件</td>
<td>swap为swap</td>
<td></td>
<td>defaults</td>
<td>0从不</td>
<td>0不自检</td>
</tr>
<tr>
<td>LABEL</td>
<td></td>
<td></td>
<td>acl</td>
<td>1每天</td>
<td>1，首先自检，通常根是1</td>
</tr>
<tr>
<td>UUID</td>
<td></td>
<td></td>
<td>noatime</td>
<td>2隔天</td>
<td>2 次级自检</td>
</tr>
<tr>
<td>伪文件系统proc，sysfs，tmpfs</td>
<td></td>
<td></td>
<td>noexec</td>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>mount -a： 可自动挂载定义在此文件中的所有支持的自动挂载的设备</p>
<h3 id="两个命令："><a href="#两个命令：" class="headerlink" title="两个命令："></a>两个命令：</h3><pre><code>du：估计文件空间使用率;
    -h: 以人类可读的格式打印尺寸（例如1K 234M 2G）
    -s: 对于目录，不包括子目录的大小;
df：报告文件系统磁盘空间使用情况;
    -l: 将列表限制为本地文件系统;
    -h: 以1024的幂为单位的打印尺寸（例如1023M）
    -i: 列出索引节点信息而不是块使用情况;
    -a: 包括伪，重复，不可访问的文件系统;</code></pre>
    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item"></div>
      <div class="post-nav-item">
    <a href="/2020/05/05/103-Text-to-AscII-Art/" rel="next" title="Text to AscII Art">
      Text to AscII Art <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#文件系统的使用-挂载和卸载"><span class="nav-number">1.</span> <span class="nav-text">文件系统的使用 挂载和卸载</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#mount命令："><span class="nav-number">1.1.</span> <span class="nav-text">mount命令：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#光盘设备一般为："><span class="nav-number">1.1.0.1.</span> <span class="nav-text">光盘设备一般为：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#挂载U盘："><span class="nav-number">1.1.0.2.</span> <span class="nav-text">挂载U盘：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#挂载本地回环设备；"><span class="nav-number">1.1.0.3.</span> <span class="nav-text">挂载本地回环设备；</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查看当前已挂载的设备"><span class="nav-number">1.1.1.</span> <span class="nav-text">查看当前已挂载的设备:</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看挂载设备被哪些进程所占用"><span class="nav-number">1.2.</span> <span class="nav-text">查看挂载设备被哪些进程所占用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#终止所有正在访问某挂载点的进程："><span class="nav-number">1.3.</span> <span class="nav-text">终止所有正在访问某挂载点的进程：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#umount命令："><span class="nav-number">1.4.</span> <span class="nav-text">umount命令：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#交换分区"><span class="nav-number">1.5.</span> <span class="nav-text">交换分区</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设定除根文件系统以外的其他文件系统能够开机时自动挂载：-etc-fstab文件"><span class="nav-number">1.6.</span> <span class="nav-text">设定除根文件系统以外的其他文件系统能够开机时自动挂载： &#x2F;etc&#x2F;fstab文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#两个命令："><span class="nav-number">1.7.</span> <span class="nav-text">两个命令：</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lcxiao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://163.com/" title="http:&#x2F;&#x2F;163.com" rel="noopener" target="_blank">163</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://baidu.com/" title="http:&#x2F;&#x2F;baidu.com" rel="noopener" target="_blank">baidu</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="/dalipan.com" title="dalipan.com">dalipan</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://google.com/" title="https:&#x2F;&#x2F;google.com" rel="noopener" target="_blank">Google</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lcxiao</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
